using JGSY.CMS.LowCode.Platform.Domain.Interfaces;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities.Monitoring;

/// <summary>
/// 监控错误日志实体
/// 记录前端 JavaScript 错误和异常
/// </summary>
public class MonitorErrorLog : ITenantEntity
{
    /// <summary>
    /// 主键ID
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 会话ID - 用于关联同一用户会话的错误
    /// </summary>
    public string SessionId { get; set; } = string.Empty;

    /// <summary>
    /// 用户ID - 可选，用于用户维度的错误分析
    /// </summary>
    public string? UserId { get; set; }

    /// <summary>
    /// 错误类型 - javascript-error, promise-rejection, network-error, react-error
    /// </summary>
    public string ErrorType { get; set; } = string.Empty;

    /// <summary>
    /// 错误消息
    /// </summary>
    public string? ErrorMessage { get; set; }

    /// <summary>
    /// 错误堆栈信息
    /// </summary>
    public string? ErrorStack { get; set; }

    /// <summary>
    /// 错误发生的文件名
    /// </summary>
    public string? ErrorFilename { get; set; }

    /// <summary>
    /// 错误发生的行号
    /// </summary>
    public int? ErrorLineNumber { get; set; }

    /// <summary>
    /// 错误发生的列号
    /// </summary>
    public int? ErrorColumnNumber { get; set; }

    /// <summary>
    /// 页面URL - 错误发生时的页面地址
    /// </summary>
    public string PageUrl { get; set; } = string.Empty;

    /// <summary>
    /// 用户代理字符串
    /// </summary>
    public string? UserAgent { get; set; }

    /// <summary>
    /// 错误严重程度 - low, medium, high, critical
    /// </summary>
    public string Severity { get; set; } = "medium";

    /// <summary>
    /// 错误状态 - new, investigating, resolved, ignored
    /// </summary>
    public string Status { get; set; } = "new";

    /// <summary>
    /// 错误指纹 - 用于错误去重标识
    /// </summary>
    public string? Fingerprint { get; set; }

    /// <summary>
    /// 时间戳 - JavaScript Date.now() 毫秒时间戳
    /// </summary>
    public long Timestamp { get; set; }

    /// <summary>
    /// 创建时间 - 数据库记录创建时间
    /// </summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 租户标识符
    /// </summary>
    public string TenantId { get; set; } = string.Empty;
}
